#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Views for the Forum webapp.
#
# Created on 2008-10-28.
# $Id$
#


import datetime
import random

from django.template import loader
from django.template import Context

from django.http import HttpResponse
from django.http import HttpResponseNotFound


from afcpweb.apps.forum import resources
from afcpweb.apps.forum.config import Config
from afcpweb.apps.common import utils


#---------------------------------------------------------------------------------------------------
# Home page, 404 not-found page, error page and static pages
#---------------------------------------------------------------------------------------------------


def home(request, lang=None):
	"Display ths Forum home page."

	if lang is None:
		lang = "zh-cn"
		
	ctxt_dict = { "url" : request.path,
	              "lang_code" : lang,
	    	      "banner_image" : random.choice(resources.BANNER_IMAGES), }
				  
	ctxt = Context(ctxt_dict)
	tmpl = loader.get_template("%s/%s/home.html" % (Config.APP_NAME, lang) )
	return HttpResponse(tmpl.render(ctxt))
	
def visitor(request, name=None, lang=None):	
	"Display the Forum visitor page"
	
	supage_name = "visitors"
	if name is None:
		name = "program"

	if lang is None:
		lang = "zh-cn"
			
	ctxt_dict = { "supage_name": supage_name,
	              "page_name" : name,
	              "url" : request.path,
	              "lang_code"    : lang, }
				  
	ctxt = Context(ctxt_dict)
	tmpl = loader.get_template("%s/%s/static/visitors/%s.html" % (Config.APP_NAME, lang, name) )
	return HttpResponse(tmpl.render(ctxt))


def exhibitor(request, name=None, lang=None):	
	"Display the Forum visitor page"
	
	supage_name = "exhibitors"
	
	if name is None:
		name = "letter"  
	
	if lang is None:
		lang = "zh-cn"
	
	ctxt_dict = { "url" : request.path,
	              "lang_code"    : lang,	
	              "supage_name": supage_name,
	              "page_name" : name, }
	ctxt = Context(ctxt_dict)
	tmpl = loader.get_template("%s/%s/static/exhibitors/%s.html" % (Config.APP_NAME,  lang, name) )
	return HttpResponse(tmpl.render(ctxt))
	
	
def contact(request, name=None, lang=None):
	"Display the Forum contact page."
	
	if lang is None:
		lang = "zh-cn"
	
	if name is None:
		name = "contact"
		
	ctxt_dict = {"url" : request.path,
	             "lang_code" : lang,
	             "supage_name" : "contact",
	             "page_name" : name, }
					
	ctxt = Context(ctxt_dict)
	tmpl = loader.get_template("%s/%s/static/contact/%s.html" % (Config.APP_NAME, lang, name));
	return HttpResponse(tmpl.render(ctxt))
	

def not_found(request):
	"Displays the 404 not-found page."
    
	ctxt_dict = { "url" : request.path, }
	ctxt = Context(ctxt_dict)
	tmpl = loader.get_template("%s/not_found.html" % Config.APP_NAME)
	return HttpResponseNotFound(tmpl.render(ctxt))

